<?php
/**
 * Created by PhpStorm.
 * User: u
 * Date: 2019/3/26
 * Time: 11:10
 */

namespace common\sources\write\taskshopimage;

use common\models\craftsman\TaskShopImage;
use Yii;

class TaskShopImageAccess implements ITaskShopImageAccess
{
    public function addTaskShop($param)
    {
        $res = Yii::$app->db->createCommand()->insert('task_shop_image', [
            'bus_id' => $param['bus_id'],
            'task_commod_id' => $param['task_commod_id'],
            'praise_type' => $param['praise_type'],
            'comment_keyword' => isset($param['comment_keyword']) ? $param['comment_keyword'] : '',
            'slide_img1' => isset($param['slide_img1']) ? $param['slide_img1']: '' ,
            'slide_img2' => isset($param['slide_img2']) ? $param['slide_img2'] : '',
            'slide_img3' => isset($param['slide_img3']) ? $param['slide_img3'] : '',
            'slide_img4' => isset($param['slide_img4']) ? $param['slide_img4'] : '',
            'slide_img5' => isset($param['slide_img5']) ? $param['slide_img5'] : '',
            'colour' => isset($param['colour']) ? $param['colour'] : '',
            'size' => isset($param['size']) ? $param['size'] : '',
            'comment' => isset($param['comment']) ? $param['comment'] : '',
            'create_time' => time()
        ])->execute();
        return $res;
    }
    public function delTaskShop($task_commod_id)
    {
        return TaskShopImage::deleteAll(['task_commod_id' => $task_commod_id]);
    }

    public function modifyTaskShop($data)
    {
        $sql = 'UPDATE ' . TaskShopImage::tableName() . ' SET is_effect = :is_effect,update_time = :update_time WHERE id = :id ';
        return Yii::$app->db->createCommand($sql)
            ->bindValues([
                ':is_effect' => $data['is_effect'],
                ':update_time' => time(),
                ':id' => $data['id']
            ])->execute();
    }
}